package connect2congress.client;

import com.google.gwt.widgetideas.graphics.client.Color;
import connect2congress.client.legacy.Point;

/**
 * Created by IntelliJ IDEA.
 * User: peter
 * Date: Mar 6, 2010
 * Time: 5:44:17 PM
 * To change this template use File | Settings | File Templates.
 */
public class Indicator {

    private final static Color INDICATOR_COLOR = new Color(35,35,245);

    public final static float INDIC_HEIGHT = 14;
    public final static float INDIC_WIDTH = 20;

    public Point loc;
    private Point prevLoc;
    Timeline parent;

    public Indicator(Timeline parent) {
        //super(parent);
        this.parent = parent;
    }

    public void setup() {

    }

    public void draw() {
        parent.setFillStyle(Indicator.INDICATOR_COLOR);
        parent.setStrokeStyle(Indicator.INDICATOR_COLOR);
        //parent.stroke(1);
        parent.beginPath();
        parent.moveTo(topX(),topY());
        parent.lineTo(leftX(),leftY());
        parent.lineTo(bottomX(),bottomY());
        parent.lineTo(topX(),topY());
        parent.closePath();
       // parent.stroke();
        parent.fill();
    }

    public boolean mousePressed(double x, double y) {

        /*System.out.println("x " + x + " y " + y);
        System.out.println("rightX " + rightX());
        System.out.println("leftX " + leftX());
        System.out.println("tipY " + tipY());
        System.out.println("leftY " + leftY());*/
        if(x <= topX() && x >= leftX() && y <= bottomY() && y >= topY()) {
            //System.out.println("Pressed on");
            return true;
        } else return false;
    }

    public void setLoc(Point locInConstraint) {
        if(prevLoc == null) {
            prevLoc = locInConstraint;
        }

        loc = locInConstraint;
        System.out.println(loc);
    }

    public void mouseReleased() {

        if(loc != prevLoc) {
            System.out.println("moved!");
            
            parent.indicatorMoved(loc);

            prevLoc = loc;

        }
    }

    public Point getLoc() {
        return loc;
    }


    public double leftX() { return this.loc.x; }
    public double leftY() { return this.loc.y; }
    public double topX() { return this.loc.x+Indicator.INDIC_WIDTH;}
    public double topY() { return this.loc.y - Indicator.INDIC_HEIGHT/2;}
    public double bottomX() { return this.loc.x+INDIC_WIDTH;}
    public double bottomY() { return this.loc.y + INDIC_HEIGHT/2;}
}
